<html xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro"  >
<link th:href="@{/layui/css/layui.css}" rel="stylesheet"/>
<head th:include="admin/common/resource ::commonHead('首页')" ></head>
<body>
    <div class="container-fluid">
        <div class="toolbar btn-group-sm" role="toolbar" >
            <h6 style="margin-top: 10px;margin-bottom: 20px" > 后台管理系统 / 分类管理 / 分类列表 </h6>
            <div style="margin-bottom: 10px;" >
                <button shiro:hasPermission="category:add" onclick="loadPage('/admin/category/add')" type="button" class="btn btn-sm btn-success"> 添加分类 </button>
                <button type="button" class="btn btn-sm btn-primary"> 导出 </button>
            </div>
        </div>
        <table class="table">
            <thead>
            <tr>
                <th scope="col"> ID </th>
                <th scope="col"> 分类名称 </th>
                <th scope="col"> 分类图标 </th>
                <th scope="col"> 所属分类 </th>
                <th scope="col"> 状态 </th>
                <th scope="col"> 操作 </th>
            </tr>
            </thead>
            <tbody>
            <tr th:each="item:${pager.list}" >
                <th scope="row" th:text="${item.id}" ></th>
                <td th:text="${item.cName}"></td>
                <td> <img style="height: 40px" th:src="${imageService+item.icon}" alt="">  </td>
                <td th:text="${item.pName}"> </td>
                <td th:text="${item.status} == 1?'正常':'禁用'" > 正常 </td>
                <td>
                    <a shiro:hasPermission="category:add" class="btn-outline-success" th:href="@{'/admin/category/add?id='+${item.id}}">添加子分类</a>
                    <a shiro:hasPermission="category:edit" class="btn-outline-primary" th:href="@{'/admin/category/edit?id='+${item.id}}">编辑</a>
                    <a shiro:hasPermission="category:delete" class="btn-outline-danger" th:href="@{'javascript:destroy('+${item.id}+')'}">删除</a>
                </td>
            </tr>
            </tbody>
        </table>
        <!-- 分页 -->
        <div th:replace="admin/common/pager ::page_pager(${pager.currentPage},0,${pager.totalPage}, @{/admin/category/list})"></div>
    </div>
</body>

</div>
<div th:include="admin/common/resource ::footerJs"></div>
<script th:src="@{/layui/layui.all.js}"></script>
<script>
    function destroy(id){
        layer.confirm('真的删除这个分类吗?', function(index){
            layer.close(index);
            //向服务端发送删除指令
            $.ajax({
                type:'delete',
                url: "/admin/category/delete",
                data: {
                    id: id
                },
                success: function (data) {
                    if(data.status == 1){
                        layer.msg("成功",function () {
                            window.location.reload();
                        },2000)
                    }else{
                        layer.msg("失败")
                    }
                }
            })
        });
    }
</script>
</html>